//package com.ymatou.paymentproxy.testcase;
//
//import org.junit.After;
//import org.junit.AfterClass;
//import org.junit.Before;
//import org.junit.BeforeClass;
//import org.junit.Ignore;
//import org.junit.Test;
//import org.junit.experimental.categories.Category;
//
//import com.ymatou.paymentproxy.parameter.AcquireOrderBean;
//import com.ymatou.paymentproxy.parameter.AliPayNotifyBean;
//import com.ymatou.paymentproxy.parameter.RefundNotifyBean;
//import com.ymatou.paymentproxy.service.RefundNotifyCall;
//import com.ymt.core.tool.FormatUtil;
//import com.ymt.core.tool.Logger;
//import com.ymt.util.DataManager;
//import com.ymt.utils.annotation.TestCase;
//import com.ymt.utils.annotation.TestSuite;
//import com.ymt.utils.tag.P1;
//import com.ymttest.business.data.Sign;
//import com.ymttest.business.service.PaymentProxyCallService;
//import com.ymttest.database.model.PPBussinessOrder;
//import com.ymttest.database.model.PPPayment;
//import com.ymttest.database.model.RefundRequest;
//import com.ymttest.database.sqlwapper.PaymentDefaultWapper;
//import com.ymttest.utils.TestDataManager;
//import com.ymttest.utils.YMTDateUtil;
//
///**
// * 退款回调 FreeMaker Template自动生成代码
// */
//@TestSuite
//public class Ts_RefundNotify {
//	private static RefundNotifyBean refundnotifyBean;
//	private static RefundNotifyCall refundnotifyCall;
//
//	@BeforeClass
//	public static void setUp() {
//		Logger.createResultFile("退款回调");
//	}
//
//	@Before
//	public void caseUp() {
//		refundnotifyBean = new RefundNotifyBean();
//		refundnotifyCall = new RefundNotifyCall();
//	}
//
//	@AfterClass
//	public static void tearDown() {
//		Logger.generateResult(refundnotifyCall.getOpurl());
//	}
//
//	@After
//	public void caseDown() {
//		Logger.end();
//	}
//
//	@Test
//	@Category({ P1.class })
//	@TestCase
//	public void Tc_RefundNotify_001() {
//		Logger.start(true, "10支付宝PC支付同步回调成功");
//		try {
//			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//			PaymentProxyCallService.acquireOrder(aqb);
//			PaymentProxyCallService.notifyCall(aqb);
//			PaymentProxyCallService.submitRefund(aqb);
//			PaymentProxyCallService.approveRefund(aqb);
//			refundnotifyBean=initRefundNotifyBean(aqb);
//			String send=aliPayRefundNotifyToSend(refundnotifyBean, aqb);
//
//			refundnotifyCall = new RefundNotifyCall("10");
//			refundnotifyCall.setData(send);
//
//			refundnotifyCall.addHeader("Mock", "1");
//			String mockid = TestDataManager.getRandomUUID().toString();
//			refundnotifyCall.addHeader("MockId", mockid);
//
//			Logger.comment("添加Mock:" + mockid);
//
//			refundnotifyCall.callService();
//			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
//
//	@Test
//	@Category({ P1.class })
//	@TestCase
//	public void Tc_RefundNotify_002() {
//		Logger.start(true, "13支付宝APP支付同步回调成功");
//		try {
//			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("13");
//			PaymentProxyCallService.acquireOrder(aqb);
//			PaymentProxyCallService.notifyCall(aqb);
//			PaymentProxyCallService.submitRefund(aqb);
//			PaymentProxyCallService.approveRefund(aqb);
//
//			refundnotifyBean=initRefundNotifyBean(aqb);
//
//			// 排序加签名
//			 String src = FormatUtil.beanToHttpString(refundnotifyBean,
//			 false);
//			String sign = new Sign().SignSHA1WithRSA(src);
//			refundnotifyBean.setSign(sign);
//			refundnotifyBean.setSign_type("RSA");
//			// 转换成最终发出的数据
//			String send = FormatUtil.beanToHttpString(refundnotifyBean, true);
//
//			refundnotifyCall = new RefundNotifyCall("13");
//			refundnotifyCall.setData(send);
//
//			refundnotifyCall.addHeader("Mock", "1");
//			String mockid = TestDataManager.getRandomUUID().toString();
//			refundnotifyCall.addHeader("MockId", mockid);
//
//			Logger.comment("添加Mock:" + mockid);
//
//			refundnotifyCall.callService();
//			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
//
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
//	@Test
//	@Category({ P1.class })
//	@TestCase
//	public void Tc_RefundNotify_003() {
//		Logger.start(true, "11支付宝wap支付同步回调成功");
//		try {
//			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("11");
//			PaymentProxyCallService.acquireOrder(aqb);
//			PaymentProxyCallService.notifyCall(aqb);
//			PaymentProxyCallService.submitRefund(aqb);
//			PaymentProxyCallService.approveRefund(aqb);
//			refundnotifyBean=initRefundNotifyBean(aqb);
//			String send=aliPayRefundNotifyToSend(refundnotifyBean, aqb);
//
//			refundnotifyCall = new RefundNotifyCall("11");
//			refundnotifyCall.setData(send);
//
//			refundnotifyCall.addHeader("Mock", "1");
//			String mockid = TestDataManager.getRandomUUID().toString();
//			refundnotifyCall.addHeader("MockId", mockid);
//
//			Logger.comment("添加Mock:" + mockid);
//
//			refundnotifyCall.callService();
//			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
//	@Test
//	@Category({ P1.class })
//	@TestCase
//	public void Tc_RefundNotify_004() {
//		Logger.start(true, "未付款就退款收到通知,失败");
//		try {
//			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//			PaymentProxyCallService.acquireOrder(aqb);
////			PaymentProxyCallService.notifyCall(aqb);
////			PaymentProxyCallService.submitRefund(aqb);
////			PaymentProxyCallService.approveRefund(aqb);
//			refundnotifyBean=initRefundNotifyBean(aqb);
//			String send=aliPayRefundNotifyToSend(refundnotifyBean, aqb);
//
//			refundnotifyCall = new RefundNotifyCall("10");
//			refundnotifyCall.setData(send);
//
//			refundnotifyCall.addHeader("Mock", "1");
//			String mockid = TestDataManager.getRandomUUID().toString();
//			refundnotifyCall.addHeader("MockId", mockid);
//
//			Logger.comment("添加Mock:" + mockid);
//
//			refundnotifyCall.callService();
//			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
//	@Test
//	@Category({ P1.class })
//	@TestCase
//	public void Tc_RefundNotify_005() {
//		Logger.start(true, "未提交退款就退款收到通知,失败");
//		try {
//			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//			PaymentProxyCallService.acquireOrder(aqb);
//			PaymentProxyCallService.notifyCall(aqb);
////			PaymentProxyCallService.submitRefund(aqb);
////			PaymentProxyCallService.approveRefund(aqb);
//			refundnotifyBean=initRefundNotifyBean(aqb);
//			String send=aliPayRefundNotifyToSend(refundnotifyBean, aqb);
//
//			refundnotifyCall = new RefundNotifyCall("10");
//			refundnotifyCall.setData(send);
//
//			refundnotifyCall.addHeader("Mock", "1");
//			String mockid = TestDataManager.getRandomUUID().toString();
//			refundnotifyCall.addHeader("MockId", mockid);
//
//			Logger.comment("添加Mock:" + mockid);
//
//			refundnotifyCall.callService();
//			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
//	@Test
//	@Category({ P1.class })
//	@TestCase
//	public void Tc_RefundNotify_006() {
//		Logger.start(true, "未审核退款就退款收到通知,收到错误警告(手工验证)");
//		try {
//			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
//			PaymentProxyCallService.acquireOrder(aqb);
//			PaymentProxyCallService.notifyCall(aqb);
//			PaymentProxyCallService.submitRefund(aqb);
////			PaymentProxyCallService.approveRefund(aqb);
//			refundnotifyBean=initRefundNotifyBean(aqb);
//			String send=aliPayRefundNotifyToSend(refundnotifyBean, aqb);
//
//			refundnotifyCall = new RefundNotifyCall("10");
//			refundnotifyCall.setData(send);
//
//			refundnotifyCall.addHeader("Mock", "1");
//			String mockid = TestDataManager.getRandomUUID().toString();
//			refundnotifyCall.addHeader("MockId", mockid);
//
//			Logger.comment("添加Mock:" + mockid);
//
//			refundnotifyCall.callService();
//			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
//			//错误警告手工验证
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
//
//	private RefundNotifyBean initRefundNotifyBean(AcquireOrderBean aqb) throws Exception {
//		refundnotifyBean=new RefundNotifyBean();
//		try{
//		refundnotifyBean.setNotify_time(DataManager.getSysTime());
//		refundnotifyBean.setNotify_type("batch_refund_notify");
//		refundnotifyBean.setNotify_id(TestDataManager.getClientpaymentId());
//		PPBussinessOrder ppb = new PaymentDefaultWapper().selectPPBussinessorderByOrderId(aqb.getOrderId()).get(0);
//		String businessoid = ppb.getBussinessOrderId();
//		PPPayment ppm = new PaymentDefaultWapper().selectPPPaymentByBussinessOrderId(businessoid).get(0);
//		RefundRequest RefundRequest = new PaymentDefaultWapper().selectRefundRequestByPaymentid(ppm.getPaymentId()).get(
//				0);
//		String result_details=aqb.getOrderId()+"^"+aqb.getPayPrice()+"^SUCCESS$ap.ymt@ymatou.com^2088701734809577^0.01^SUCCESS";
//		refundnotifyBean.setResult_details(result_details);
//		refundnotifyBean.setBatch_no(RefundRequest.getRefundBatchNo());
//		refundnotifyBean.setSuccess_num("1");
//		}catch(Exception e){
//			Logger.debug(e.getMessage());
//		}
//		return refundnotifyBean;
//	}
//	
//	private String aliPayRefundNotifyToSend(RefundNotifyBean refundNotifyBean, AcquireOrderBean aqb) throws Exception {
//		Logger.comment("aliPayRefundNotify加签并转换为SendString");
//		String send = null;
//		if (aqb.getPayType().equals("13")) {
//			// 排序加签名
//			String src = FormatUtil.beanToHttpString(refundNotifyBean, false);
//			String sign =  new Sign().SignSHA1WithRSA(src);
//			refundNotifyBean.setSign(sign);
//			refundNotifyBean.setSign_type("RSA");
//			// 转换成最终发出的数据
//			send = FormatUtil.beanToHttpString(refundNotifyBean, true);
//		} else {
//			String src = FormatUtil.beanToHttpString(refundNotifyBean, false);
//			String sign = new Sign().signMd5(refundNotifyBean, Sign.autoTestKey);
//			refundNotifyBean.setSign(sign);
//			refundNotifyBean.setSign_type("MD5");
//			send = FormatUtil.beanToHttpString(refundNotifyBean, true);
//		}
//		return send;
//	}
//
//}
